package com.azier.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author 金建强(ptma@163.com)
 * @version 2018/5/7 18:14
 */
public class DbUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(DbUtil.class);

    public static void close(Connection conn) {
        try {
            if (conn != null && !conn.isClosed()){
                conn.close();
                conn = null;
            }
        } catch (SQLException e) {
            LOGGER.error("Close Connection Error: {}", e.getMessage(), e);
        }
    }

    public static  void close(ResultSet rs) {
        try {
            if (rs != null){
                rs.close();
                rs = null;
            }
        } catch (SQLException e) {
            LOGGER.error("Close ResultSet Error: {}", e.getMessage(), e);
        }
    }

    public static  void close(Statement st) {
        try {
            if (st != null){
                st.close();
                st = null;
            }
        } catch (SQLException e) {
            LOGGER.warn("Close Statement Error: {}", e.getMessage(), e);
        }
    }
}
